﻿/**
* @author ZhangHuihua@msn.com
*/
(function($) {
    var _lookup = { currentGroup: "", suffix: "", $target: null, pk: "id", $callback: null };
    var _util = {
        _lookupPrefix: function(key) {
            var strDot = _lookup.currentGroup ? "." : "";
            return _lookup.currentGroup + strDot + key + _lookup.suffix;
        },
        lookupPk: function(key) {
            return this._lookupPrefix(key);
        },
        lookupField: function(key) {
            return this.lookupPk(key);
        }
    };

    $.extend({
        bringBackSuggest: function(args) {

            var $box = _lookup['$target'].parents(".unitBox:first");

            $box.find(":input").each(function() {

                var $input = $(this), inputName = $input.attr("name");
                var inputId = $input.attr("id");
                for (var key in args) {
                    var name = (_lookup.pk == key) ? _util.lookupPk(key) : _util.lookupField(key);

                    if (name == inputName || name == inputId) {
                        $input.val(args[key]);
                        break;
                    }
                }
            });

            $box.find("a").each(function() {
                var $this = $(this);
                var $thisName = $this.attr("name");
                var $thisText = $this.attr("tvalue");
                if (!$thisName || !$thisText) return;
                for (var key in args) {
                    var name = (_lookup.pk == key) ? _util.lookupPk(key) : _util.lookupField(key);
                    name = name.replaceForId();

                    $thisText = $thisText.replaceAll(name, args[key]);
                    $thisName = $thisName.replaceAll(name, args[key]);
                }

                if ($thisText != $this.attr("tvalue") || $this.text() == '') {
                    $this.text($thisText);
                }
                if ($thisName != $this.attr("name")) {
                    $this.attr("href", $thisName);
                }
            });

            //            var inputs = $(":input", $box).not('[readonly]');
            //            var idx = inputs.index(_lookup['$target']);
            //            idx++;
            //            if (idx < inputs.length) {
            //                inputs[idx].focus();
            //            }
        },
        bringBack: function(args) {
            $.bringBackSuggest(args);
            $.pdialog.closeCurrent();
        },
        itemBringBack: function(args) {
            if (_lookup.$callback) {
                _lookup.$callback(args);
            }
            else {
                $.bringBack(args[0]);
            }
        }
    });

    $.fn.extend({
        lookup: function() {
            return this.each(function() {
                var $this = $(this), options = { mask: true,
                    width: $this.attr('width') || 860, height: $this.attr('height') || 400,
                    maxable: eval($this.attr("maxable") || "true"),
                    resizable: eval($this.attr("resizable") || "true")
                };
                $this.click(function(event) {
                    _lookup = $.extend(_lookup, {
                        currentGroup: $this.attr("lookupGroup") || "",
                        suffix: $this.attr("suffix") || "",
                        $target: $this,
                        pk: $this.attr("lookupPk") || "id",
                        $callback: null
                    });

                    var url = unescape($this.attr("href")).replaceTmById($(event.target).parents("form:first"));
                    if (!url.isFinishedTm()) {
                        alertMsg.error($this.attr("warn") || bee.msg("alertSelectMsg"));
                        return false;
                    }

                    $.pdialog.open(url, "_blank", $this.attr("title") || $this.text(), options);
                    return false;
                });
            });
        },
        multLookup: function() {
            return this.each(function() {
                var $this = $(this), args = {};
                $this.click(function(event) {
                    var $unitBox = $this.parents(".unitBox:first");
                    $unitBox.find("[name='" + $this.attr("multLookup") + "']").filter(":checked").each(function() {
                        var _args = bee.jsonEval($(this).val());
                        for (var key in _args) {
                            var value = args[key] ? args[key] + "," : "";
                            args[key] = value + _args[key];
                        }
                    });

                    if ($.isEmptyObject(args)) {
                        alertMsg.error($this.attr("warn") || bee.msg("alertSelectMsg"));
                        return false;
                    }
                    $.bringBack(args);
                });
            });
        },
        suggest: function() {
            var op = { suggest$: "#suggest", suggestShadow$: "#suggestShadow" };
            var selectedIndex = -1;
            return this.each(function() {
                var $input = $(this).attr('autocomplete', 'off').keydown(function(event) {
                    if (event.keyCode == bee.keyCode.ENTER && $(op.suggest$).is(':visible')) return false; //屏蔽回车提交
                });

                var suggestFields = $input.attr('suggestFields').split(",");

                function _show(event) {
                    var offset = $input.offset();
                    var iTop = offset.top + this.offsetHeight;
                    var $suggest = $(op.suggest$);
                    if ($suggest.size() == 0) $suggest = $('<div id="suggest"></div>').appendTo($('body'));

                    $suggest.css({
                        left: offset.left + 'px',
                        top: iTop + 'px'
                    }).show();

                    _lookup = $.extend(_lookup, {
                        currentGroup: $input.attr("lookupGroup") || "",
                        suffix: $input.attr("suffix") || "",
                        $target: $input,
                        pk: $input.attr("lookupPk") || "id",
                        $callback: null
                    });

                    var url = unescape($input.attr("suggestUrl")).replaceTmById($(event.target).parents(".unitBox:first"));
                    url = unescape($input.attr("suggestUrl")).replaceTmById($(event.target).parents("form:first"));
                    if (!url.isFinishedTm()) {
                        alertMsg.error($input.attr("warn") || bee.msg("alertSelectMsg"));
                        return false;
                    }

                    var postData = {};
                    postData[$input.attr("postField") || "inputValue"] = $input.val();

                    bee.PostData(url, postData, function(result) {
                        var html = '';

                        $.each(result, function(i) {
                            var liAttr = '', liLabel = '';

                            for (var i = 0; i < suggestFields.length; i++) {
                                var str = this[suggestFields[i]];
                                if (str) {
                                    if (liLabel) liLabel += '-';
                                    liLabel += str;
                                }
                            }
                            for (var key in this) {
                                if (liAttr) liAttr += ',';
                                liAttr += key + ":'" + this[key] + "'";
                            }
                            html += '<li lookupAttrs="' + liAttr + '">' + liLabel + '</li>';
                        });

                        var $lis = $suggest.html('<ul>' + html + '</ul>').find("li");

                        var $container = $('#container');
                        var cheight = $container.offset().top + $container.height();
                        if ($suggest.offset().top + $suggest.height() > cheight) {
                            $suggest.css("top", $suggest.offset().top - $suggest.height() - $input.height() + 'px');
                        }

                        $lis.hoverClass("selected").click(function() {
                            _select($(this));
                        });
                        if ($lis.size() == 1 && event.keyCode != bee.keyCode.BACKSPACE) {
                            _select($lis.eq(0));
                        } else if ($lis.size() == 0) {
                            var jsonStr = "";
                            for (var i = 0; i < suggestFields.length; i++) {
                                if (_util.lookupField(suggestFields[i]) == event.target.name) {
                                    break;
                                }
                                if (jsonStr) jsonStr += ',';
                                jsonStr += suggestFields[i] + ":''";
                            }
                            jsonStr = "{" + _lookup.pk + ":''," + jsonStr + "}";
                            $.bringBackSuggest(bee.jsonEval(jsonStr));
                        }
                    });

                    $(document).bind("click", _close);
                    return false;
                }
                function _select($item) {
                    var jsonStr = "{" + $item.attr('lookupAttrs') + "}";

                    $.bringBackSuggest(bee.jsonEval(jsonStr));
                }
                function _close() {
                    $(op.suggest$).html('').hide();
                    selectedIndex = -1;
                    $(document).unbind("click", _close);
                }

                $input.focus(_show).click(_show).keyup(function(event) {
                    var $items = $(op.suggest$).find("li");
                    switch (event.keyCode) {
                        case bee.keyCode.ESC:
                        case bee.keyCode.TAB:
                        case bee.keyCode.SHIFT:
                        case bee.keyCode.HOME:
                        case bee.keyCode.END:
                        case bee.keyCode.LEFT:
                        case bee.keyCode.RIGHT:
                            break;
                        case bee.keyCode.ENTER:
                            _close();
                            break;
                        case bee.keyCode.DOWN:
                            if (selectedIndex >= $items.size() - 1) selectedIndex = -1;
                            else selectedIndex++;
                            break;
                        case bee.keyCode.UP:
                            if (selectedIndex < 0) selectedIndex = $items.size() - 1;
                            else selectedIndex--;
                            break;
                        default:
                            _show(event);
                    }
                    $items.removeClass("selected");
                    if (selectedIndex >= 0) {
                        var $item = $items.eq(selectedIndex).addClass("selected");
                        _select($item);
                    }
                });
            });
        },

        itemDetail: function() {
            return this.each(function() {
                var $table = $(this).css("clear", "both"), $tbody = $table.find("tbody");
                $('<input type="hidden" name="bee_itemNum" value="0"/>').insertBefore($table);

                var noopFlag = $table.hasClass("protect");

                var fields = [];

                if (!noopFlag) {
                    $(":input", $tbody).live("keydown", function(e) {
                        if (e.which == bee.keyCode.ENTER) {
                            var $box = $(this).parents(".unitBox:first");
                            var inputs = $(":text", $box).not('[readonly]');
                            var idx = inputs.index(this);
                            if ($(this).hasClass("required") && $(this).val().trim() == '') {
                                return;
                            }

                            if (idx == inputs.length - 1) {
                                var nextBox = $box.next();
                                if (nextBox.length == 1) {
                                    var nextinputs = nextBox.find(":text").not('[readonly]').not('[suggesturl]');
                                    if (nextinputs.length > 0) {
                                        $(nextinputs[0]).focus();
                                    }
                                }
                                else {
                                    var $btnAdd = $box.parents(".page:first").find(".addButton");
                                    if ($btnAdd.length == 1) {
                                        $btnAdd.trigger("click");
                                    }
                                }
                            }
                            else {
                                $(inputs[idx + 1]).focus();
                            }
                            return false;
                        }
                    });
                }

                $table.find("tr:first th[type]").each(function(i) {
                    var $th = $(this);
                    var field = {
                        type: $th.attr("type") || "text",
                        patternDate: $th.attr("format") || "yyyy-MM-dd",
                        name: $th.attr("name") || "",
                        defaultVal: $th.attr("defaultVal") || "",
                        size: $th.attr("size") || "12",
                        enumUrl: $th.attr("enumUrl") || "",
                        lookupGroup: $th.attr("lookupGroup") || "",
                        lookupUrl: $th.attr("lookupUrl") || "",
                        lookupPk: $th.attr("lookupPk") || "id",
                        suggestUrl: $th.attr("suggestUrl"),
                        suggestFields: $th.attr("suggestFields"),
                        postField: $th.attr("postField") || "",
                        fieldClass: $th.attr("fieldClass") || "",
                        fieldAttrs: $th.attr("fieldAttrs") || ""
                    };
                    fields.push(field);
                });

                $tbody.find("a.btnDel").click(function() {

                    if (noopFlag) return;

                    var $btnDel = $(this);

                    if ($btnDel.is("[href^=javascript:]")) {
                        $btnDel.parents("tr:first").remove();
                        initSuffix($tbody);
                        return false;
                    }

                    function delDbData() {
                        $.ajax({
                            type: 'POST', dataType: "json", url: $btnDel.attr('href'), cache: false,
                            success: function() {
                                $btnDel.parents("tr:first").remove();
                                initSuffix($tbody);
                            },
                            error: bee.ajaxError
                        });
                    }

                    if ($btnDel.attr("title")) {
                        alertMsg.confirm($btnDel.attr("title"), { okCall: delDbData });
                    } else {
                        delDbData();
                    }

                    return false;
                });

                var $buttonContent = null;
                if (!noopFlag) {
                    $buttonContent = $('<div class="topFormBar"><ul></ul></div>').insertBefore($table).find("ul");
                }

                var addButTxt = $table.attr('addButton') || "Add New";
                if (addButTxt && !noopFlag) {
                    var $addBut = $buttonContent.append('<li><a class="button addButton"><span>' + addButTxt + '</span></a></li>').find("a");
                    var $rowNum = $('<input type="hidden" name="bee_rowNum" class="textInput" style="margin:2px;" value="1" size="2"/>').insertBefore($table);

                    var trTm = "";
                    $addBut.click(function() {
                        if (!trTm) trTm = trHtml(fields);

                        var $tr = $(trTm);
                        $tr.appendTo($tbody).initUI().find("a.btnDel").click(function() {
                            $(this).parents("tr:first").remove();
                            initSuffix($tbody);
                            return false;
                        });

                        initSuffix($tbody);
                        $(":text:first", $tr).focus().select();
                    });
                }

                var $tfoot = $("tfoot", $table);
                if ($tfoot.length) {
                    var footFields = [];
                    $("tr:first td[tvalue]", $tfoot).each(function(i) {
                        var $td = $(this);
                        var tvalue = $td.attr("tvalue");

                        var rvalue = tvalue.substring(tvalue.indexOf('{') + 1, tvalue.indexOf('}'));
                        rvalue = rvalue.replace(/\[(.*?)\]/g, 'items[#index#].$1')
                        var footField = {
                            target: $td,
                            tvalue: tvalue,
                            rvalue: rvalue,
                            name: tvalue.substring(tvalue.indexOf('{'), tvalue.indexOf('}') + 1)
                        };
                        footFields.push(footField);
                    });

                    $(":text", $tbody).live('blur', function() {
                        var $tr = $(this).parent().parent();
                        refreshComputerField($tr);
                        refreshFootComputerField();
                    });
                }

                function refreshComputerField(trParent) {
                    var $computerField = trParent.find(".computerField");
                    if ($computerField.length) {
                        var txtname = $computerField.attr("name");
                        txtname = txtname.substring(0, txtname.indexOf('.'));
                        var txtvalue = $computerField.attr("tvalue");
                        txtvalue = txtvalue.replace(/\[(.*?)\]/g, txtname + '.$1');
                        $computerField.val(computeValue(trParent, txtvalue).toString().formatNumber(2));
                    }
                }

                function refreshFootComputerField() {
                    var trs = $tbody.find('>tr');
                    $(footFields).each(function() {
                        var field = this;
                        var total = 0;
                        trs.each(function(i) {
                            var txtname = field.rvalue.replaceAll("#index#", i);
                            total += computeValue($(this), txtname);
                        });
                        if (total > 0) {
                            total = total.toString().formatNumber(2);
                        }
                        field.target.text(field.tvalue.replace(field.name, total));
                    });
                }

                function computeValue(trParent, expression) {
                    if (expression.indexOf("*") < 0) {
                        var txtname = expression.replaceForId();
                        var $txt = trParent.find("[name=" + txtname + "]");
                        return parseFloat($txt.val());
                    }
                    else {
                        var expression = expression.replaceForId();
                        var index = expression.indexOf("*");
                        var txtname1 = expression.substring(0, index);
                        var txtname2 = expression.substring(index + 1, expression.length);
                        var $txt1 = trParent.find("[name=" + txtname1 + "]");
                        var $txt2 = trParent.find("[name=" + txtname2 + "]");
                        return parseFloat($txt1.val() * $txt2.val());
                    }
                }

                function multiAdd(args) {
                    for (var key in args) {
                        var trTm = trHtml(fields);
                        var $tr = $(trTm);

                        $tr.find(":input").each(function() {
                            var $input = $(this), inputName = $input.attr("name");
                            for (var item in args[key]) {
                                var name = (_lookup.pk == item) ? _util.lookupPk(item) : _util.lookupField(item);

                                if (name == inputName) {
                                    $input.val(args[key][item]);
                                    break;
                                }
                            }
                        });

                        $tr.find("a").each(function() {
                            var $this = $(this);
                            var $thisName = $this.attr("name");
                            var $thisText = $this.attr("tvalue");
                            if (!$thisName) return;
                            for (var item in args[key]) {
                                var name = (_lookup.pk == item) ? _util.lookupPk(item) : _util.lookupField(item);
                                name = name.replaceForId();
                                $thisText = $thisText.replaceAll(name, args[key][item]);
                                $thisName = $thisName.replaceAll(name, args[key][item]);
                            }
                            $this.text($thisText);
                            $this.attr("href", $thisName);
                        });

                        $tr.appendTo($tbody).initUI().find("a.btnDel").click(function() {
                            $(this).parents("tr:first").remove();
                            initSuffix($tbody);
                            return false;
                        });
                    }

                    initSuffix($tbody);
                }

                var clearButTxt = $table.attr("clearButton");
                if (clearButTxt && !noopFlag) {
                    var $clearBut = $('<li><a class="button"><span>' + clearButTxt + '</span></a></li>');
                    $buttonContent.append($clearBut);
                    $clearBut.click(function() {
                        $tbody.empty();
                    });
                }

                var multiAddButTxt = $table.attr("multiAddButton");
                var mulitAddUrl = $table.attr("multiAddUrl");
                if (multiAddButTxt && !noopFlag) {
                    var $multiAddBut = $('<li><a class="button"><span>' + multiAddButTxt + '</span></a></li>');
                    $buttonContent.append($multiAddBut);
                    $multiAddBut.click(function() {
                        _lookup = $.extend(_lookup, {
                            $callback: multiAdd,
                            currentGroup: $table.attr("itemGroup")
                        });
                        var options = { mask: true,
                            width: 860,
                            height: 420, maxable: true
                        };

                        var url = unescape(mulitAddUrl).replaceTmById($(this).parents("form:first"));
                        if (!url.isFinishedTm()) {
                            alertMsg.error(bee.msg("alertSelectMsg"));
                            return false;
                        }

                        $.pdialog.open(url, "_blank", multiAddButTxt, options);
                        return false;

                    });
                }

                initSuffix($tbody);

                // Init computer field
                var trs = $tbody.find('>tr');
                trs.each(function() {
                    refreshComputerField($(this));
                });
                refreshFootComputerField();
            });


            /**
            * 删除时重新初始化下标
            */
            function initSuffix($tbody) {
                var trs = $tbody.find('>tr');
                var $itemNum = $tbody.parents(".page:first").find("input[name=bee_itemNum]");
                if ($itemNum.length) $itemNum.val(trs.length);
                trs.each(function(i) {
                    $(':input, a.btnLook, span, a', this).each(function() {
                        var $this = $(this), name = $this.attr('name'), val = $this.val();

                        if (name) $this.attr('name', name.replaceSuffix(i));

                        var lookupGroup = $this.attr('lookupGroup');
                        if (lookupGroup) { $this.attr('lookupGroup', lookupGroup.replaceSuffix(i)); }

                        var suffix = $this.attr("suffix");
                        if (suffix) { $this.attr('suffix', suffix.replaceSuffix(i)); }

                        if (!$this.is("select")) {
                            var text = $this.text();
                            if (text) { $this.text(text.replaceSuffix(i)); }
                        }

                        var href = $this.attr("href");
                        if (href) { $this.attr("href", href.replaceSuffix(i)); }

                        var max = $this.attr("max");
                        if (max) { $this.attr('max', max.replaceSuffix(i)); }

                        var max = $this.attr("tvalue");
                        if (max) { $this.attr('tvalue', max.replaceSuffix(i)); }

                        var max = $this.attr("id");
                        if (max) { $this.attr('id', max.replaceSuffix(i)); }

                        var max = $this.attr("suggesturl");
                        if (max) { $this.attr('suggesturl', max.replaceSuffix(i)); }

                        if (val && val.indexOf("#index#") >= 0) $this.val(val.replace('#index#', i + 1));
                        if ($this.is('span')) {
                            $this.html($this.html().replaceSuffix(i + 1));
                        }

                    });
                });
            }

            function tdHtml(field) {
                var html = '', suffix = '';

                if (field.name.endsWith("[#index#]")) suffix = "[#index#]";
                else if (field.name.endsWith("[]")) suffix = "[]";

                var suffixFrag = suffix ? ' suffix="' + suffix + '" ' : '';

                var attrFrag = '';
                if (field.fieldAttrs) {
                    var attrs = bee.jsonEval(field.fieldAttrs);
                    for (var key in attrs) {
                        attrFrag += key + '="' + attrs[key] + '"';
                    }
                }
                switch (field.type) {
                    case 'del':
                        html = '<a href="javascript:void(0)" class="btnDel ' + field.fieldClass + '">删除</a>';
                        break;
                    case 'lookup':
                        var suggestFrag = '';
                        if (field.suggestFields) {
                            suggestFrag = 'autocomplete="off" lookupGroup="' + field.lookupGroup + '"' + suffixFrag + ' suggestUrl="' + field.suggestUrl + '" suggestFields="' + field.suggestFields + '"' + ' postField="' + field.postField + '"';
                        }

                        html = '<input type="hidden" name="' + field.lookupGroup + '.' + field.lookupPk + suffix + '"/>'
							+ '<input type="text" name="' + field.name + '"' + suggestFrag + ' lookupPk="' + field.lookupPk + '" size="' + field.size + '" class="' + field.fieldClass + '"/>'
							+ '<a class="btnLook" href="' + field.lookupUrl + '" lookupGroup="' + field.lookupGroup + '" ' + suggestFrag + ' lookupPk="' + field.lookupPk + '" title="查找选择">查找选择</a>';
                        break;
                    case 'sugguest':
                        var suggestFrag = '';
                        if (field.suggestFields) {
                            suggestFrag = 'autocomplete="off" lookupGroup="' + field.lookupGroup + '"' + suffixFrag + ' suggestUrl="' + field.suggestUrl + '" suggestFields="' + field.suggestFields + '"' + ' postField="' + field.postField + '"';
                        }

                        html = '<input type="hidden" name="' + field.lookupGroup + '.' + field.lookupPk + suffix + '"/>'
							+ '<input type="text" name="' + field.name + '"' + suggestFrag + ' lookupPk="' + field.lookupPk + '" size="' + field.size + '" class="' + field.fieldClass + '"/>'
                        break;
                    case 'attach':
                        html = '<input type="hidden" name="' + field.lookupGroup + '.' + field.lookupPk + suffix + '"/>'
							+ '<input type="text" name="' + field.name + '" size="' + field.size + '" readonly="readonly" class="' + field.fieldClass + '"/>'
							+ '<a class="btnAttach" href="' + field.lookupUrl + '" lookupGroup="' + field.lookupGroup + '" ' + suggestFrag + ' lookupPk="' + field.lookupPk + '" width="560" height="300" title="查找选择">查找选择</a>';
                        break;
                    case 'enum':

                        $.ajax({
                            type: "POST", dataType: "json", async: false,
                            url: field.enumUrl,
                            data: { inputName: field.name },
                            success: function(json) {
                                if (!json.status) {
                                    if (json.message && alertMsg) alertMsg.error(json.message);
                                }
                                else {
                                    html = json.result;
                                }
                            }
                        });
                        break;
                    case 'date':
                        html = '<input type="text" name="' + field.name + '" value="' + field.defaultVal + '" class="date ' + field.fieldClass + '" format="' + field.patternDate + '" size="' + field.size + '"/>'
							+ '<a class="inputDateButton" href="javascript:void(0)">选择</a>';
                        break;
                    case 'label':
                        html = '<span>' + field.defaultVal + '</span>';
                        break;
                    case 'link':
                        html = '<a name="' + field.name + '" tvalue="' + field.defaultVal + '" class="' + field.fieldClass + '" ' + attrFrag + '></a>';
                        break;
                    default:
                        html = '<input type="text" name="' + field.name + '" value="' + field.defaultVal + '" size="' + field.size + '" class="' + field.fieldClass + '" ' + attrFrag + '/>';
                        break;
                }
                return '<td>' + html + '</td>';
            }
            function trHtml(fields) {
                var html = '';
                $(fields).each(function() {
                    html += tdHtml(this);
                });
                return '<tr class="unitBox">' + html + '</tr>';
            }
        },

        selectedTodo: function() {

            function _getIds(selectedIds, targetType) {
                var ids = "";
                var $box = targetType == "dialog" ? $.pdialog.getCurrent() : navTab.getCurrentPanel();
                $box.find("input:checked").filter("[name='" + selectedIds + "']").each(function(i) {
                    var val = $(this).val();
                    ids += i == 0 ? val : "," + val;
                });
                return ids;
            }
            return this.each(function() {
                var $this = $(this);
                var selectedIds = $this.attr("rel") || "ids";
                var postType = $this.attr("postType") || "map";

                $this.click(function() {
                    var ids = _getIds(selectedIds, $this.attr("targetType"));
                    if (!ids) {
                        alertMsg.error($this.attr("warn") || bee.msg("alertSelectMsg"));
                        return false;
                    }
                    function _doPost() {
                        $.ajax({
                            type: 'POST', url: $this.attr('href'), dataType: 'json', cache: false,
                            data: function() {
                                if (postType == 'map') {
                                    return $.map(ids.split(','), function(val, i) {
                                        return { name: selectedIds, value: val };
                                    })
                                } else {
                                    var _data = {};
                                    _data[selectedIds] = ids;
                                    return _data;
                                }
                            } (),
                            success: navTabAjaxDone,
                            error: bee.ajaxError
                        });
                    }
                    var title = $this.attr("title");
                    if (title) {
                        alertMsg.confirm(title, { okCall: _doPost });
                    } else {
                        _doPost();
                    }
                    return false;
                });

            });
        }
    });
})(jQuery);

